using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class MassSendImgItem : BaseMassSendElement
	{
		private const string TAG = "MassSendImgItem";
		private Image image_0;
		private Grid imgGrid;
		private string mImgSrc;
		private bool _contentLoaded;
		public MassSendImgItem()
		{
			this.InitializeComponent();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			this.image_0 = (base.GetTemplateChild("img") as Image);
			this.imgGrid = (base.GetTemplateChild("imgGrid") as Grid);
		}
		private void RefreshImgSrc()
		{
			if (this.image_0 == null)
			{
				return;
			}
			if (string.IsNullOrEmpty(this.mImgSrc))
			{
				this.SetEmptyImage();
				return;
			}
			BitmapImage bitmapImage = ImageCacheMgr.loadImage(this.mImgSrc, ImageCacheType.MsgImg);
			if (bitmapImage == null)
			{
				Log.smethod_1("MassSendImgItem", "RefreshImgSrc:GetImageFromPath==null,mImgSrc:" + this.mImgSrc);
				this.SetEmptyImage();
				return;
			}
			this.image_0.set_Source(bitmapImage);
			this.image_0.set_Stretch(1);
			double num = 234.0 / (double)bitmapImage.get_PixelWidth();
			double num2 = 223.0 / (double)bitmapImage.get_PixelHeight();
			double num3 = (num < num2) ? num : num2;
			this.image_0.set_Width((double)bitmapImage.get_PixelWidth() * num3);
			this.image_0.set_Height((double)bitmapImage.get_PixelHeight() * num3);
			this.imgGrid.set_Width(this.image_0.get_Width() + 10.0);
			this.imgGrid.set_Height(this.image_0.get_Height() + 29.0);
		}
		public override void SetImgSrc(string ImgSrc)
		{
			this.mImgSrc = ImgSrc;
			this.RefreshImgSrc();
		}
		private void SetEmptyImage()
		{
			this.image_0.set_Source(new ImageSourceConverter().ConvertFromString("/Resource/Img/Chat/empty_img_nor.png") as ImageSource);
			this.image_0.set_Width(60.0);
			this.image_0.set_Height(60.0);
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/MassSend/UI/MassSendImgItem.xaml", 2));
		}
	}
}
